<?php
// 设计一个有getMin功能的栈
class GetMinStack {
    public $stackData = [];
    public $stackMin = [];

    public function push($value) {
        if (empty($this->stackMin)) {
            $this->stackMin[] = $value;
        } else if ($value <= $this->getMin()) {
            $this->stackMin[] = $value;
        }
        $this->stackData[] = $value;
    }

    public function getMin() {
        return $this->stackMin[0];
    }

    public function pop() {
        if (empty($this->stackData)) {
            throw new Exception('StackData is empty');
        }
        $value = array_pop($this->stackData);

        if($value == $this->getMin()) {
            array_pop($this->stackMin);
        }
        return $value;
    }
}

$stack = new GetMinStack();
$stack->push(1);
$stack->push(2);
$stack->push(3);
$stack->push(4);
$stack->push(5);
$stack->push(6);
$value = $stack->getMin();
